<ui:composition template="/dynamic/layout/layout.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="content">
		<div id="welcome">
			<p style="clear: both" />
		</div>
		<h3>Grupy</h3>
		<h:form id="formGroup">
			<p:dataTable id="dataTable" var="group"
				value="#{groupMBean.myGroups}" rows="12" paginator="true"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="9,12,15" paginatorPosition="bottom"
				widgetVar="groupTable" filteredValue="#{groupMBean.filteredGroups}"
				emptyMessage="Nie znaleziono żadnych grup.">
				<f:facet name="header">
					<p:outputPanel style="float:right">
						<h:outputText value="Szukaj w grupach:" />
						<p:inputText id="globalFilter" onkeyup="groupTable.filter()"
							style="width:150px" />
					</p:outputPanel>
				</f:facet>

				<p:column sortBy="name" headerText="Nazwa grupy" filterBy="name"
					filterMatchMode="contains">
					<h:outputText value="#{group.name}" />
				</p:column>
				<p:column sortBy="dateFrom" headerText="Data powstania grupy"
					filterBy="dateFrom" filterMatchMode="contains">
					<h:outputText value="#{group.dateFrom}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</p:column>

				<p:column sortBy="department.school.name" headerText="Uczelnia"
					filterBy="department.school.name" filterMatchMode="contains">
					<h:outputText value="#{group.department.school.name}" />
				</p:column>

				<p:column sortBy="department.name" headerText="Wydział"
					filterBy="department.name" filterMatchMode="contains">
					<h:outputText value="#{group.department.name}" />
				</p:column>
				<p:column headerText="Akcje">
					<div class="action-div">
						<p:commandLink title="Pokaż" action="#{groupMBean.showGroup}"
							ajax="false">
							<img
								src="${facesContext.externalContext.requestContextPath}/static/images/pokaz.PNG"
								alt="Pokaz" />
							<f:param value="#{group.idGroup}" name="groupId" />
						</p:commandLink>
						<p:commandLink title="Edytuj" action="#{groupMBean.editGroup}"
							ajax="false"
							rendered="#{request.isUserInRole('ROLE_ADMIN') or group.createUser.username eq userMBean.loggedUser.username}">
							<img
								src="${facesContext.externalContext.requestContextPath}/static/images/edytuj.PNG"
								alt="Edytuj" />
							<f:param value="#{group.idGroup}" name="groupId" />
						</p:commandLink>
						<p:commandLink title="Usuń" action="#{groupMBean.removeGroup}"
							ajax="false"
							rendered="#{request.isUserInRole('ROLE_ADMIN')}">
							<img
								src="${facesContext.externalContext.requestContextPath}/static/images/kosz.PNG"
								alt="Usuń" />
							<f:param value="#{group.idGroup}" name="groupId" />
						</p:commandLink>
					</div>
				</p:column>
			</p:dataTable>
			<p:commandButton id="addnewgroup" action="#{groupMBean.addGroup}"
				value="Dodaj grupe" ajax="false" />
		</h:form>
		<div id="main_content"></div>

	</ui:define>
</ui:composition>